using UnityEngine;

namespace ProceduralPrimitivesUtil
{
	public static class ProceduralPrimitives
	{
		private static GameObject CreateBase()
		{
			GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
			gameObject.GetComponent<MeshFilter>().mesh = null;
			Object.Destroy(gameObject.GetComponent<Collider>());
			return gameObject;
		}

		public static GameObject CreateInstance(PPBase source = null)
		{
			GameObject gameObject = CreateBase();
			gameObject.name = "Procdural Primitive Instance";
			gameObject.AddComponent<PPInstance>().ApplySource(source);
			return gameObject;
		}

		public static GameObject CreateCombiner()
		{
			GameObject gameObject = CreateBase();
			gameObject.name = "Procdural Primitive Combiner";
			gameObject.AddComponent<PPCombiner>();
			return gameObject;
		}

		public static GameObject CreatePrimitive(ProceduralPrimitiveType type)
		{
			GameObject gameObject = CreateBase();
			gameObject.name = type.ToString();
			switch (type)
			{
			case ProceduralPrimitiveType.Plane:
				gameObject.AddComponent<Plane>();
				break;
			case ProceduralPrimitiveType.Circle:
				gameObject.AddComponent<Circle>();
				break;
			case ProceduralPrimitiveType.Ring:
				gameObject.AddComponent<Ring>();
				break;
			case ProceduralPrimitiveType.Triangle:
				gameObject.AddComponent<Triangle>();
				break;
			case ProceduralPrimitiveType.Trapezoid:
				gameObject.AddComponent<Trapezoid>();
				break;
			case ProceduralPrimitiveType.ChamferPlane:
				gameObject.AddComponent<ChamferPlane>();
				break;
			case ProceduralPrimitiveType.Capsule:
				gameObject.AddComponent<Capsule>();
				break;
			case ProceduralPrimitiveType.Prism:
				gameObject.AddComponent<Prism>();
				break;
			case ProceduralPrimitiveType.ChamferBox:
				gameObject.AddComponent<ChamferBox>();
				break;
			case ProceduralPrimitiveType.ChamferCylinder:
				gameObject.AddComponent<ChamferCylinder>();
				break;
			case ProceduralPrimitiveType.DoubleSphere:
				gameObject.AddComponent<DoubleSphere>();
				break;
			case ProceduralPrimitiveType.Arrow:
				gameObject.AddComponent<Arrow>();
				break;
			case ProceduralPrimitiveType.Box:
				gameObject.AddComponent<Box>();
				break;
			case ProceduralPrimitiveType.Sphere:
				gameObject.AddComponent<Sphere>();
				break;
			case ProceduralPrimitiveType.Cylinder:
				gameObject.AddComponent<Cylinder>();
				break;
			case ProceduralPrimitiveType.Cone:
				gameObject.AddComponent<Cone>();
				break;
			case ProceduralPrimitiveType.Tube:
				gameObject.AddComponent<Tube>();
				break;
			case ProceduralPrimitiveType.RectTube:
				gameObject.AddComponent<RectTube>();
				break;
			case ProceduralPrimitiveType.Torus:
				gameObject.AddComponent<Torus>();
				break;
			case ProceduralPrimitiveType.Pyramid:
				gameObject.AddComponent<Pyramid>();
				break;
			}
			return gameObject;
		}
	}
}
